// greedy alg.
// 两条短边之和>第三边
// sort. Traverse from more to less. Select biggest as third side of triangle.
package main

import "sort"

func largestPerimeter(nums []int) int {
	sort.Ints(nums)
	res := 0
	for i := len(nums) - 1; i >= 2; i-- {
		if nums[i-2]+nums[i-1] > nums[i] {
			res = nums[i-2] + nums[i-1] + nums[i]
		}
	}
	return res
}

func main() {
	arr := []int{3, 2, 3, 4}
	largestPerimeter(arr)
}
